//
//  Button+Extension.swift
//  微博
//
//  Created by qiukai on 16/4/6.
//  Copyright © 2016年 仇恺. All rights reserved.
//

import UIKit

extension UIButton{
    
    convenience init(imageName: String, backImageName: String)
    {
        self.init()
        
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        setImage(UIImage(named: "\(imageName)_highlighted"), forState: UIControlState.Highlighted)
        setBackgroundImage(UIImage(named: backImageName), forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: UIControlState.Highlighted)
        
        // 会根据背景图片的大小调整尺寸
        sizeToFit()
    }
    /// 按钮的便利构造
    ///
    /// - parameter imageName: 图片名称
    /// - parameter Color:     颜色
    /// - parameter title:     文字
    ///
    /// - returns: 按钮对象
    convenience init(imageName: String, Color: UIColor, title: String)
    {
        self.init()
        
        setTitle(title, forState: .Normal)
        setTitleColor(Color, forState: .Normal)
        setBackgroundImage(UIImage(named: imageName), forState: .Normal)
    }
    
}